package cn.mju.tankfighterbackend.dao

import cn.mju.tankfighterbackend.entity.CustomerUser
import jakarta.persistence.LockModeType
import org.springframework.data.jpa.repository.Lock
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.CrudRepository
import org.springframework.stereotype.Repository


@Repository
interface CustomerUserRepository : CrudRepository<CustomerUser, Long> {
    fun getUserByUserName(userName: String?): CustomerUser?

    @Lock(value = LockModeType.PESSIMISTIC_FORCE_INCREMENT)
    fun existsByUserName(userName: String?): Boolean

    fun countByUserName(userName: String?): Long

    fun findAllByUserName(userName: String?):List<CustomerUser>

    @Query("select user_name from Customer_User group by user_name having count(user_name)>1", nativeQuery = true)
    fun findRepeatUsers():List<String>
}